package com.ruoyi.web.controller.system;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.NucleicAcidLog;
import com.ruoyi.system.domain.Student;
import com.ruoyi.system.service.INucleicAcidLogService;
import com.ruoyi.system.service.IStudentService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

/**
 * NucleicAcidLogController
 *
 * @author ruoyi
 * @date 2023-01-08
 */
@Controller
@RequestMapping("/system/NucleicAcidLog")
public class NucleicAcidLogController extends BaseController {
    private String prefix = "system/NucleicAcidLog";

    @Autowired
    private INucleicAcidLogService nucleicAcidLogService;
    @Autowired
    private IStudentService studentService;

    @RequiresPermissions("system:NucleicAcidLog:view")
    @GetMapping()
    public String NucleicAcidLog(ModelMap modelMap) {
        modelMap.put("sdudents", studentService.selectStudentList(new Student()));
        return prefix + "/NucleicAcidLog";
    }

    /**
     * 查询NucleicAcidLog列表
     */
    @RequiresPermissions("system:NucleicAcidLog:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(NucleicAcidLog nucleicAcidLog) {
        startPage();
        String smpled = nucleicAcidLog.getSpmpled();
        List<NucleicAcidLog> list = new ArrayList<>(10);
        if ("2".equals(smpled)) {
            list = nucleicAcidLogService.selectUnNucleicAcidLogList(nucleicAcidLog);
        }else {
           list = nucleicAcidLogService.selectNucleicAcidLogList(nucleicAcidLog);
        }

        return getDataTable(list);
    }

    /**
     * 导出NucleicAcidLog列表
     */
    @RequiresPermissions("system:NucleicAcidLog:export")
    @Log(title = "NucleicAcidLog", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(NucleicAcidLog nucleicAcidLog) {
        List<NucleicAcidLog> list = nucleicAcidLogService.selectNucleicAcidLogList(nucleicAcidLog);
        ExcelUtil<NucleicAcidLog> util = new ExcelUtil<NucleicAcidLog>(NucleicAcidLog.class);
        return util.exportExcel(list, "NucleicAcidLog数据");
    }

    /**
     * 新增NucleicAcidLog
     */
    @GetMapping("/add")
    public String add(ModelMap modelMap) {
        modelMap.put("sdudents", studentService.selectStudentList(new Student()));
        return prefix + "/add";
    }

    /**
     * 新增保存NucleicAcidLog
     */
    @RequiresPermissions("system:NucleicAcidLog:add")
    @Log(title = "NucleicAcidLog", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(NucleicAcidLog nucleicAcidLog) {
        return toAjax(nucleicAcidLogService.insertNucleicAcidLog(nucleicAcidLog));
    }

    /**
     * 修改NucleicAcidLog
     */
    @RequiresPermissions("system:NucleicAcidLog:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap) {
        NucleicAcidLog nucleicAcidLog = nucleicAcidLogService.selectNucleicAcidLogById(id);
        mmap.put("nucleicAcidLog", nucleicAcidLog);
        mmap.put("sdudents", studentService.selectStudentList(new Student()));
        return prefix + "/edit";
    }

    /**
     * 修改保存NucleicAcidLog
     */
    @RequiresPermissions("system:NucleicAcidLog:edit")
    @Log(title = "NucleicAcidLog", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(NucleicAcidLog nucleicAcidLog) {
        return toAjax(nucleicAcidLogService.updateNucleicAcidLog(nucleicAcidLog));
    }

    /**
     * 删除NucleicAcidLog
     */
    @RequiresPermissions("system:NucleicAcidLog:remove")
    @Log(title = "NucleicAcidLog", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(nucleicAcidLogService.deleteNucleicAcidLogByIds(ids));
    }

    /**
     * 查询某位同学 7 日内完成的核酸采样情况
     */
    @RequiresPermissions("system:NucleicAcidLog:list")
    @PostMapping("/getSevenDay")
    @ResponseBody
    public TableDataInfo getSevenDay(String studentId) {
        startPage();
        List<NucleicAcidLog> list = nucleicAcidLogService.selectSevenDayNucleicAcidLogByStudentId(studentId);
        return getDataTable(list);
    }
}
